package com.hxzy.config;

import com.hxzy.config.filter.RepeatableFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 在springmvc框架配置 servlet中的Filter类
 * web 2.5配置
 * <filter>
 *     <filter-name>repeatableFilter</filter-name>
 *     <filter-class>com.hxzy.config.filter.RepeatableFilter</filter-class>
 * </filter>
 *
 * <filter-mapping>
 *     <filter-name>repeatableFilter</filter-name>
 *     <url-pattern>/*</url-pattern>
 * </filter-mapping>
 *
 *
 * 以前web3.0的注解
 * @WebFilter(urlPattern="/*")
 */
@Configuration
public class FilterConfig {

    /**
     * 注册Filter
     * @return
     */
    @Bean
    public FilterRegistrationBean someFilterRegistration()
    {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        //设定一个Filter
        registration.setFilter(new RepeatableFilter());
        //设定拦截器地址
        registration.addUrlPatterns("/*");
        registration.setName("repeatableFilter");

        // Filter执行顺序(数字越大，越优先执行)
        registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE);
        return registration;
    }

}
